<?php

	class Smin extends rsrcHandle{
		
		private $constructed = false;
		
		function __construct(){}
		
		function set_pid($id, $skip=1){
			if($this->constructed) return;
			parent::__construct(Cache::pathto("/dev/stdin/$id"), $skip);
			$this->constructed = true;
		}
		
		function getlines($timeout=30){
			$this->set_pid(INSTANCE, 2);
			if(!$this->try_open('r', $timeout, array(smout(), 'is_resource'))) return NULL;
			$data = '';
			while($ln = $this->read(4096)) $data .= $ln;
			$this->close();
			return $data;
		}
		
		function putlines($data, $timeout=30){
			if(!$this->try_open('a', $timeout, array(smout(), 'is_resource'))) return false;
			if(!sm_endswith($data, "\n")) $data .= "\n";
			$n = $this->write($data);
			$this->close();
			return $n;
		}

	}


